package dao;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.handlers.BeanListHandler;


import org.apache.commons.lang.RandomStringUtils;

import bean.User;
import jdbcutils.JDBCUtils;


public class registerDao {
	public static List<User> checkUser(String username){
		String sql = "select *from users where username = ?";
		try {
			return JDBCUtils.getQr().query(sql, username, new BeanListHandler<>(User.class));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static int addUser(User user) {
		String userid = RandomStringUtils.random(12, "abcdefghizklmnABCDEFGLIZKLMN123456789");
		String sql="insert into users (userid,username,password,phone,gender) values(?,?,?,?,?)";
		try {
			return JDBCUtils.getQr().update(sql, userid,user.getUsername(),user.getPassword(),user.getPhone(),user.getGender());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}
}
